package nyist.media.utils;

import com.alibaba.fastjson.JSON;
import lombok.extern.log4j.Log4j2;
import nyist.media.page.ApiResult;
import org.springframework.http.MediaType;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

/**
 * 渲染工具类
 *
 * @author dcf
 */
@Log4j2
public class RenderUtil {

    /**
     * 读取json
     *
     * @param response  响应对象
     * @param apiResult 状态码和状态信息
     */
    public static void readJson(HttpServletResponse response, ApiResult apiResult, String error) {

        try {
            response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
            response.setCharacterEncoding("UTF-8");
            response.getOutputStream().write(JSON.toJSONString(apiResult.getMap(error)).getBytes());
        } catch (IOException e) {
            log.error("响应信息转换失败", e.getMessage());
            e.printStackTrace();
        }
    }



}
